var router = new Router("con");
var request = new Request();

var indexList = new IndexList();
var personInfo = new PersonInfo();
var login = new Login();
var register = new Register();
var addContent = new AddContent();

var isLogin = false;

$(function(){
	
	layui.use(['layer'], function(){
	  var laypage = layui.laypage,
	  layer = layui.layer;
	})
	
	router.route("indexList.html", indexList);
	init();
})

init = function(){
	
	//logo的点击
	$("#logo").click(function(){
		router.route("indexList.html", indexList);
	});
	//退出的点击
	$("#logout").click(logout);
	//新增下拉的点击
	$("#addContent li").click(function(){
		var data = $(this).text();
		router.route("addContent.html", addContent, data);
	});
	//新增的鼠标滑过
	$("#add").mousemove(function(){
		$(this).removeClass("glyphicon glyphicon-plus");
		$(this).addClass("glyphicon glyphicon-triangle-bottom");
	});
	$("#add").mouseout(function(){
		$(this).removeClass("glyphicon glyphicon-triangle-bottom");
		$(this).addClass("glyphicon glyphicon-plus");
	});
	//设置未登陆
	setIsLogin(false);
}

setIsLogin = function(data){
	console.log("..........");
	isLogin = data;
	var addr = "";
	var btnText = "";
	var controller;
	
	if(isLogin){
		addr = "personInfo.html";
		btnText = "我的";
		controller = personInfo;
		$("#logout").css("display", "");
		$("#okAdd").css("display", "");
	}else{
		addr = "login.html";
		btnText = "登陆/注册";
		controller = login;
		$("#logout").css("display", "none");
		$("#okAdd").css("display", "none");
	}
	$("#interLogin").unbind('click');
	$("#interLogin").click(function(){
		console.log($(this).text());
		router.route(addr, controller);
	});
	$("#interLogin").text(btnText);
}

function logout(){
	setIsLogin(false);
	layer.msg('退出');
	router.route("indexList.html", indexList);
}
